﻿#ifndef GRAPHICSAIRVALVEITEM_H
#define GRAPHICSAIRVALVEITEM_H

#include <QGraphicsObject>
#include <QPoint>
#include <QLine>

class GraphicsAirValveItem : public QGraphicsObject
{
    Q_OBJECT
public:
    enum Direction {Left, Right, Up, Down};
    GraphicsAirValveItem();
    virtual QPointF keyPoint(int i);
    QRectF boundingRect() const override;
public slots:
    void setDir(enum Direction dir);
    void setEnable(bool enable);
signals:
    void valveStateChanged(bool on);
protected:
    void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
    void drawStateOn(QPainter *painter, enum Direction dir);
    void drawStateOff(QPainter *painter, enum Direction dir);
protected:
    Direction m_dir = Right;
    bool m_enable = true;

    QPoint m_pointsUp[3];
    QPoint m_pointsDown[3];
    QPoint m_pointsLeft[3];
    QPoint m_pointsRight[3];

    QLine m_lineH[2]; // off 状态的水平线
    QLine m_lineV[2]; // off 状态的竖直线

    int m_radius = 25;
    int m_width;
    int m_height;
};

#endif // GRAPHICSAIRVALVEITEM_H
